package com.cloudbench.logic;

import java.util.ArrayList;
import java.util.logging.Logger;

import org.json.JSONObject;

import android.content.Context;
import android.util.Log;
import ch.boye.httpclientandroidlib.NameValuePair;
import ch.boye.httpclientandroidlib.message.BasicNameValuePair;

import com.cloudbench.util.StringUtil;
import com.cloudbench.util.WebClient;
import static com.cloudbench.common.Constants.appServerUrl;



public class NodeService {
	private static final String CNAME = NodeService.class.getSimpleName();
	private String rUrl;
	////
	
	//
    public static NodeService newInstance() {
            // loadSessionInfo();
            return new NodeService();
    }
	
	public String getStringContent(Context c, String content, String guestbookName, int timeout) throws Exception {
		if (StringUtil.isEmpty(appServerUrl()))
            throw new Exception("AppServerUrl is null...");

	    rUrl = appServerUrl();

        Log.d(CNAME, "app Server.url = " + rUrl);

		ArrayList <NameValuePair> params = new ArrayList <NameValuePair>();
        params.add(new BasicNameValuePair("content", content));
        params.add(new BasicNameValuePair("guestbookName", guestbookName));

		String result = WebClient.post(c, rUrl, params, timeout);
		//String reWebClient.get(c, rUrl, "s");
		Log.d(CNAME, result);
	    if (result == null || result.isEmpty()) {
            return null;
	    }


		return result;
	}
}
